import Vue from 'vue'
import VueRouter from 'vue-router'

const pageBox = () => import('@/views/pageBox/pageBox.vue')
const login = () => import('@/views/login/login.vue')
const home = () => import('@/views/home/home.vue')
const cardBin = () => import('@/components/cardBin/cardBin.vue')
const funMgr = () => import('@/components/funMgr/funMgr.vue')
const dicManage = () => import('@/components/dicManage/dicList.vue')
const opnList = () => import('@/components/opnList/opnList.vue')
const proMag = () => import('@/components/porMag/proMag.vue')
const smsChnMan = () => import('@/components/smsChnMan/smsChnMan.vue')
const emailchn = () => import('@/components/emailchn/emailchn.vue')
const emailchnctn = () => import('@/components/emailchnctn/emailchnctn.vue')
const faqmgmt = () => import('@/components/faqmgmt/faqmgmt.vue')
// const smsResChn = () => import('@/components/smsResChn/smsResChn.vue')

const merAud = () => import('@/components/merAud/merAud.vue')
const perAud = () => import('@/components/perAud/perAud.vue')
const busAud = () => import('@/components/busAud/busAud.vue')
const cngAud = () => import('@/components/cngAud/cngAud.vue')
const ramAccAud = () => import('@/components/ramAccAud/ramAccAud.vue')
const freOrder = () => import('@/components/freOrder/freOrder.vue')
const moneyAudit = () => import('@/components/moneyAudit/moneyAudit.vue')
const prosingaudit = () => import('@/components/prosingaudit/prosingaudit.vue')
const apphmbanr = () => import('@/components/apphmbanr/apphmbanr.vue')
const setmtrusaud = () => import('@/components/setmtrusaud/setmtrusaud.vue')

const roleMgr = () => import('@/components/roleMgr/rolemgr.vue')
const oprMgr = () => import('@/components/oprMgr/oprMgr.vue')

const transRecords = () => import('@/components/transManage/transRecords.vue')

const disRec = () => import('@/components/disRec/disRec.vue')
const monRec = () => import('@/components/monRec/monRec.vue')
const setRec = () => import('@/components/setRec/setRec.vue')
const detailsofpay = () => import('@/components/detailsofpay/detailsofpay.vue')

const appEf = () => import('@/components/appEf/appEf.vue')
const annMgr = () => import('@/components/annMgr/annMgr.vue')
const logMgr = () => import('@/components/logMgr/logMgr.vue')
const staMgr = () => import('@/components/staMgr/staMgr.vue')
const noteMgr = () => import('@/components/noteMgr/noteMgr.vue')
const timeTk = () => import('@/components/timeTask/timeTask.vue')
const appversion = () => import('@/components/appversion/appversion.vue')

const risktypelist = () => import('@/components/risktypelist/risktypelist.vue')
const riskrecord = () => import('@/components/riskrecord/riskrecord.vue')

const errCode = () => import('@/components/errCode/errCode.vue')
const chnList = () => import('@/components/chnList/chnList.vue')
const prdList = () => import('@/components/prdList/prdList.vue')
const bankList = () => import('@/components/bankList/bankList.vue')

const comHand = () => import('@/components/comHand/comHand.vue')
const feedback = () => import('@/components/feedback/feedback.vue')

const merList = () => import('@/components/merManage/merList/merList.vue')
const merAcc = () => import('@/components/merAcc/merAcc.vue')
const inactivemer = () => import('@/components/inactivemer/inactivemer.vue')
const setRules = () => import('@/components/setRules/setRules.vue')

const userList = () => import('@/components/userList/userList.vue')

const horData = () => import('@/components/horData/horData.vue')
const errAccRec = () => import('@/components/errAccRec/errAccRec.vue')
const bufpolData = () => import('@/components/bufpolData/bufpolData.vue')
const staQuery = () => import('@/components/staQuery/staQuery.vue')
const ledger = () => import('@/components/ledger/ledger.vue')
const notpay = () => import('@/components/notpay/notpay.vue')

const Pim = () => import('@/components/bigAuditStep/pim/pim.vue')
const OwnEnt = () => import('@/components/bigAuditStep/ownEnt/ownEnt.vue')
const CrpAcc = () => import('@/components/bigAuditStep/crpAcc/crpAcc.vue')
const CpnBiz = () => import('@/components/bigAuditStep/cpnBiz/cpnBiz.vue')
const BnsInf = () => import('@/components/bigAuditStep/bnsInf/bnsInf.vue')
const payProduct = () => import('@/views/payProduct/payProduct.vue')

const AccountInfo = () => import('@/components/merManage/merDetail/accountInfo.vue')
const BaseInfo = () => import('@/components/merManage/merDetail/baseInfo.vue')
const DeviceInfo = () => import('@/components/merManage/merDetail/deviceInfo.vue')
const LoginPwd = () => import('@/components/merManage/merDetail/loginPwd.vue')
const LoginRecord = () => import('@/components/merManage/merDetail/loginRecord.vue')
const SecretKey = () => import('@/components/merManage/merDetail/secretKey.vue')
const SettleInfo = () => import('@/components/merManage/merDetail/settleInfo.vue')
const productList = () => import('@/components/merManage/productList/productList.vue')
const clearRulesList = () => import('@/components/merManage/clearRulesList/clearRulesList.vue')
const process = () => import('@/components/process/process.vue')

const feedbackdet = () => import('@/views/feedbackdet/feedbackdet.vue')
const complaintdetails = () => import('@/views/complaintdetails/complaintdetails.vue')
const merApp = () => import('@/views/merApp/merApp.vue')
const opePro = () => import('@/views/opePro/opePro.vue')
const runHis = () => import('@/views/runHis/runHis.vue')
const notpaydet = () => import('@/views/notpaydet/notpaydet.vue')
const merDetail = () => import('@/views/merDetail/merDetail.vue')
const transDetail = () => import('@/views/transManage/transDetail.vue')
const disRecDet = () => import('@/views/disRecDet/disRecDet.vue')
const monRecDet = () => import('@/views/monRecDet/monRecDet.vue')
const merDet = () => import('@/views/merDet/merDet.vue')
const orderDet = () => import('@/views/orderDet/orderDet.vue')
const bgMer = () => import('@/views/regAudit/bigPos/merAuditBig.vue')
const ltMer = () => import('@/views/regAudit/litPos/merAuditLit.vue')
const shortNote = () => import('@/views/shortNote/shortNote.vue')
const userdetails = () => import('@/views/userdetails/userdetails.vue')
const accquery = () => import('@/views/accquery/accquery.vue')
const merledger = () => import('@/views/merledger/merledger.vue')
const monauddet = () => import('@/views/monauddet/monauddet.vue')
const sofpayDet = () => import('@/views/sofpayDet/sofpayDet.vue')
const setRecDet = () => import('@/views/setRecDet/setRecDet.vue')

const accinfo = () => import('@/views/userdetails/udet/accinfo.vue')
const paycode = () => import('@/views/userdetails/udet/paymentcode.vue')
const loginpwd = () => import('@/views/userdetails/udet/loginpwd.vue')
const essInfo = () => import('@/views/userdetails/udet/essInfo.vue')
const bankcode = () => import('@/views/userdetails/udet/bankcode.vue')
const loginlog = () => import('@/views/userdetails/udet/loginlog.vue')
const deviceInfo = () => import('@/views/userdetails/udet/deviceInfo.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  { path: '/login', component: login, meta: { pagetitle: 'Login - COCOPAY' } },
  { path: '/agreement', component: () => import('@/views/jcole.vue'), meta: { pagetitle: '' } },
  {
    path: '/',
    component: pageBox,
    children: [
      { path: '/home', component: home, meta: { pagetitle: 'Home - COCOPAY' } },
      { path: '/cardBin', component: cardBin, meta: { pagetitle: 'Card bin - COCOPAY' } },
      { path: '/sys/sysFunc', component: funMgr, meta: { pagetitle: 'Function list - COCOPAY' } },
      { path: '/sys/sysDictionary', component: dicManage, meta: { pagetitle: 'Data dictionary - COCOPAY' } },
      { path: '/opnList', component: opnList, meta: { pagetitle: 'Open interface - COCOPAY' } },
      { path: '/sysProduct/proMag', component: proMag, meta: { pagetitle: 'Product list - COCOPAY' } },
      { path: '/noteMgr', component: noteMgr, meta: { pagetitle: 'SMS management - COCOPAY' } },
      { path: '/smsChnMan', component: smsChnMan, meta: { pagetitle: 'SMS channel management - COCOPAY' } },
      { path: '/emailchnctn', component: emailchnctn, meta: { pagetitle: 'Email template - COCOPAY' } },
      { path: '/emailchn', component: emailchn, meta: { pagetitle: 'Mail channel management - COCOPAY' } },
      { path: '/faqmgmt', component: faqmgmt, meta: { pagetitle: 'FAQ management - COCOPAY' } },
      // { path: '/smsResChn', component: smsResChn },
      { path: '/merApplyOrder/merAud', component: merAud, meta: { pagetitle: 'Merchant archives audit - COCOPAY' } },
      { path: '/perAud', component: perAud, meta: { pagetitle: 'Personal real name verification - COCOPAY' } },
      { path: '/busAud', component: busAud, meta: { pagetitle: 'Merchant information change audit - COCOPAY' } },
      { path: '/cngAud', component: cngAud, meta: { pagetitle: 'Personal information change audit - COCOPAY' } },
      { path: '/ramAccAud', component: ramAccAud, meta: { pagetitle: 'Freeze/unfreeze merchant - COCOPAY' } },
      { path: '/freOrder', component: freOrder, meta: { pagetitle: 'Freeze/unfreeze order - COCOPAY' } },
      { path: '/moneyAudit', component: moneyAudit, meta: { pagetitle: 'Payment audit - COCOPAY' } },
      { path: '/prosingaudit', component: prosingaudit, meta: { pagetitle: 'Product signing/cancellation review - COCOPAY' } },
      { path: '/apphmbanr', component: apphmbanr, meta: { pagetitle: 'Banner review on app home - COCOPAY' } },
      { path: '/setmtrusaud', component: setmtrusaud, meta: { pagetitle: 'Audit list of settlement rules - COCOPAY' } },
      { path: '/sys/sysRole', component: roleMgr, meta: { pagetitle: 'Role management - COCOPAY' } },
      { path: '/sys/sysUser', component: oprMgr, meta: { pagetitle: 'Operator list - COCOPAY' } },
      { path: '/transManage/transRecords', component: transRecords, meta: { pagetitle: 'Transaction record - COCOPAY' } },
      { path: '/disRec', component: disRec, meta: { pagetitle: 'Clearing record - COCOPAY' } },
      { path: '/monRecord', component: monRec, meta: { pagetitle: 'Payment record - COCOPAY' } },
      { path: '/setRec', component: setRec, meta: { pagetitle: 'Settlement record - COCOPAY' } },
      { path: '/detailsofpay', component: detailsofpay, meta: { pagetitle: 'Receipt and disbursement - COCOPAY' } },
      { path: '/ledger', component: ledger, meta: { pagetitle: 'ledger - COCOPAY' } },
      { path: '/notyetpaid', component: notpay, meta: { pagetitle: 'List of money to be paid - COCOPAY' } },
      { path: '/appbanner/appFun', component: appEf, meta: { pagetitle: 'App home function management - COCOPAY' } },
      { path: '/annMgr', component: annMgr, meta: { pagetitle: 'Announcement management - COCOPAY' } },
      { path: '/logMgr', component: logMgr, meta: { pagetitle: 'Log management - COCOPAY' } },
      { path: '/staMgr', component: staMgr, meta: { pagetitle: 'Static resource management - COCOPAY' } },
      { path: '/timMgr', component: timeTk, meta: { pagetitle: 'Scheduled task management - COCOPAY' } },
      { path: '/sys/appversion', component: appversion, meta: { pagetitle: 'App version management - COCOPAY' } },
      { path: '/risktypelist', component: risktypelist, meta: { pagetitle: 'Risk control type list - COCOPAY' } },
      { path: '/riskrecord', component: riskrecord, meta: { pagetitle: 'Risk control trigger record - COCOPAY' } },
      { path: '/errCode', component: errCode, meta: { pagetitle: 'Channel error code - COCOPAY' } },
      { path: '/chnList', component: chnList, meta: { pagetitle: 'Channel list - COCOPAY' } },
      { path: '/prdList', component: prdList, meta: { pagetitle: 'Channel product list - COCOPAY' } },
      { path: '/bankList', component: bankList, meta: { pagetitle: 'Product support bank list - COCOPAY' } },
      { path: '/comHand', component: comHand, meta: { pagetitle: 'Complaint handling - COCOPAY' } },
      { path: '/feedback', component: feedback, meta: { pagetitle: 'Problem feedback - COCOPAY' } },
      { path: '/merManage/merList', component: merList, meta: { pagetitle: 'Merchants list - COCOPAY' } },
      { path: '/merAcc', component: merAcc, meta: { pagetitle: 'Merchant account - COCOPAY' } },
      { path: '/inactivemer', component: inactivemer, meta: { pagetitle: 'List of merchants not active - COCOPAY' } },
      { path: '/userList', component: userList, meta: { pagetitle: 'Payment user list - COCOPAY' } },
      { path: '/horData', component: horData, meta: { pagetitle: 'The flat data - COCOPAY' } },
      { path: '/errAccRec', component: errAccRec, meta: { pagetitle: 'Error account record - COCOPAY' } },
      { path: '/bufpolData', component: bufpolData, meta: { pagetitle: 'Buffer pool data - COCOPAY' } },
      { path: '/staQuery', component: staQuery, meta: { pagetitle: 'Channel billing query - COCOPAY' } },
      // { path: '/setrules', component: setRules },
      { path: '/sec/productList', component: productList, meta: { pagetitle: 'Merchant product list - COCOPAY' } },
      { path: '/sec/clearRulesList', component: clearRulesList, meta: { pagetitle: 'Settlement rule - COCOPAY' } },
      { path: '/payProduct', component: payProduct, meta: { pagetitle: 'Product and rule setup - COCOPAY' } },
      { path: '/process', component: process, meta: { pagetitle: 'Reconciliation process - COCOPAY' } },
      // { path: '/shortNote', component: shortNote },
      {
        path: '/sec/big/merAudit',
        component: bgMer,
        redirect: '/sec/big/merAudit/pim',
        children: [
          { path: '/sec/big/merAudit/pim', name: 'bigAnd', component: Pim, meta: { pagetitle: 'Personal info - COCOPAY' } },
          { path: '/sec/big/merAudit/ownEnt', component: OwnEnt, meta: { pagetitle: 'Company registration information - COCOPAY' } },
          { path: '/sec/big/merAudit/crpAcc', component: CrpAcc, meta: { pagetitle: 'Corporate accounts - COCOPAY' } },
          { path: '/sec/big/merAudit/cpnBiz', component: CpnBiz, meta: { pagetitle: 'business information - COCOPAY' } },
          { path: '/sec/big/merAudit/bnsInf', component: BnsInf, meta: { pagetitle: 'Information of enterprise principal - COCOPAY' } }
        ]
      },
      {
        path: '/sec/lit/merAudit',
        component: ltMer,
        redirect: '/sec/lit/merAudit/pim',
        children: [
          { path: '/sec/lit/merAudit/pim', name: 'litAnd', component: Pim, meta: { pagetitle: 'Personal info - COCOPAY' } },
          { path: '/sec/lit/merAudit/crpAcc', component: CrpAcc, meta: { pagetitle: 'Corporate accounts - COCOPAY' } },
          { path: '/sec/lit/merAudit/bnsInf', component: BnsInf, meta: { pagetitle: 'Information of enterprise principal - COCOPAY' } }
        ]
      },
      { path: '/sec/runHis', component: runHis, meta: { pagetitle: 'Timed task log - COCOPAY' } },
      { path: '/sec/disRecDet', component: disRecDet, meta: { pagetitle: 'Clearing record details - COCOPAY' } },
      { path: '/sec/monRecDet', component: monRecDet, meta: { pagetitle: 'Payment record details - COCOPAY' } },
      { path: '/orderDetailsForm', component: orderDet,  meta: { pagetitle: 'Personal info - COCOPAY' } },
      {
        path: '/sec/merManage/merDetail',
        component: merDetail,
        redirect: '/sec/merManage/merDetail/baseInfo',
        children: [
          { path: '/sec/merManage/merDetail/baseInfo', name: 'baseInfo', component: BaseInfo, meta: { pagetitle: 'Basic information of the merchant - COCOPAY' } },
          { path: '/sec/merManage/merDetail/settleInfo', component: SettleInfo, meta: { pagetitle: 'Billing info - COCOPAY' } },
          { path: '/sec/merManage/merDetail/accountInfo', component: AccountInfo, meta: { pagetitle: 'Merchant administrator information - COCOPAY' } },
          { path: '/sec/merManage/merDetail/secretKey', component: SecretKey, meta: { pagetitle: 'Merchant key - COCOPAY' } },
          { path: '/sec/merManage/merDetail/loginPwd', component: LoginPwd, meta: { pagetitle: 'Login password - COCOPAY' } },
          { path: '/sec/merManage/merDetail/loginRecord', component: LoginRecord, meta: { pagetitle: 'Log on to log - COCOPAY' } },
          { path: '/sec/merManage/merDetail/deviceInfo', component: DeviceInfo, meta: { pagetitle: 'equipment information - COCOPAY' } }
        ]
      },
      { path: '/sec/userdetails',
        component: userdetails,
        redirect: '/sec/userdetails/accinfo',
        children: [
          { path: '/sec/userdetails/accinfo', name: 'accinfo', component: accinfo, meta: { pagetitle: 'account information - COCOPAY' } },
          { path: '/sec/userdetails/essinfo', component: essInfo, meta: { pagetitle: 'basic information - COCOPAY' } },
          { path: '/sec/userdetails/loginpwd', component: loginpwd, meta: { pagetitle: 'login password - COCOPAY' } },
          { path: '/sec/userdetails/paycode', component: paycode, meta: { pagetitle: 'payment code - COCOPAY' } },
          { path: '/sec/userdetails/bankcode', component: bankcode, meta: { pagetitle: 'bank card - COCOPAY' } },
          { path: '/sec/userdetails/deviceInfo', component: deviceInfo, meta: { pagetitle: 'equipment information - COCOPAY' } },
          { path: '/sec/userdetails/loginlog', component: loginlog, meta: { pagetitle: 'Log on to log - COCOPAY' } }
        ]
      },
      { path: '/sec/feedbackdet', component: feedbackdet, name: 'feedbackdet', meta: { pagetitle: 'Feedbackdet details - COCOPAY' } },
      { path: '/sec/complaintdetails', component: complaintdetails, name: 'complaintdetails', meta: { pagetitle: 'Complaint details - COCOPAY' } },
      { path: '/sec/accquery', component: accquery, name: 'accquery', meta: { pagetitle: 'Account query - COCOPAY' } },
      { path: '/sec/transManage/transDetail', component: transDetail, name: 'transDetail', meta: { pagetitle: 'Transaction details - COCOPAY' } },
      { path: '/sec/merledger', component: merledger, name: 'merledger', meta: { pagetitle: 'Merchant ledger - COCOPAY' } },
      { path: '/sec/notpaydet', component: notpaydet, name: 'notpaydet', meta: { pagetitle: 'Details of pending payment - COCOPAY' } },
      { path: '/monauddet', component: monauddet, name: 'monauddet', meta: { pagetitle: 'Details of money audit - COCOPAY' } },
      { path: '/sec/sofpayDet', component: sofpayDet, name: 'sofpayDet', meta: { pagetitle: 'Details of income and expenditure - COCOPAY' } },
      { path: '/sec/setRecDet', component: setRecDet, name: 'setRecDet', meta: { pagetitle: 'Details of settlement record - COCOPAY' } }
      // { path: '/opePro', component: opePro },
      // { path: '/merDetails', component: merDet, meta: { pagetitle: 'Personal info - COCOPAY' } }
    ]
  }
]

const router = new VueRouter({
  routes,
  mode: 'history',
  base: '/maxmin'
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  if (to.path === '/agreement') return next()
  let tokenStr = window.localStorage.getItem('token')
  // 强制跳转
  if (!tokenStr && to.path !== '/agreement') return next('/login')
  // 动态添加title
  document.getElementById('public_title').innerHTML = to.meta.pagetitle === undefined ? 'COCOPAY' : to.meta.pagetitle
  // 所有验证通过,放行
  next()
})

export default router
